#!/bin/sh
#
# init script template
# (c) dangbinghoo@gmail.com.
#     playpenguin.org
#

# cmd path(don't use only cmd, that will
# not work if /etc/init.d/XXXd has a word XXX
cmd_bin="/usr/bin/XXX"
cmd_param=""
cmd_start_sleep="0" #sleep x seconds before start.

. /etc/init.d/rcfunctions

start()
{	
	# rc message functions
	if [ ! -f "${cmd_bin}" ];then
		rc_echo "this is echo for rc, and don't use echo directly"
		rc_warning "cmd XXX not found!"	
		rc_notify "cmd XXX not found!"	
		rc_error "cmd XXX not found!"	
		exit 1
	fi

	# rc_do_msg to print Starting service xxx message
	rc_do_msg "Starting XXX "
	# start/stop _daemon to start or stop a daemon
	start_daemon "${cmd_bin}" "${cmd_param}" "0" "${cmd_bin}" 
	rc_print_status
}

status()
{
	pid=`rc_check_proc_cmd "${cmd_bin}"`
	
	if [ -n "${pid}" ];then
		rc_warning "service already started with pid $pid ."
	else
		rc_warning "service not started!"
	fi
}

restart()
{
	stop
	start
}

stop()
{
	rc_do_msg "Stopping telnetd "
	stop_daemon "${cmd_bin}"
	rc_print_status
}

#
# main
#

case "$1" in
	"start")
		start;;
	"stop")	
		stop;;
	"status")	
		status;;
	"restart")
		restart;;
	*)
		echo "Usage: $0 start|stop|restart"
		exit 0
esac

